package com.happycat.controller.home;


import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.happycat.base.PageParams;
import com.happycat.base.R;
import com.happycat.home.dto.CatBannerQueryDto;
import com.happycat.mobile.model.CatBanner;
import com.happycat.mobile.service.CatBannerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author liaoyong
 * @since 2020-08-01
 */
@RestController
@RequestMapping("/catBanner")
@Api(tags = "API-Banner图", value = "banner图获取")
public class CatBannerController {
    @Autowired
	private CatBannerService catBannerService;
	
//	@ApiOperation(value = "详情")
//    @RequestMapping(method = RequestMethod.POST, value = "/detail")
//	public ResponseModel<CatBanner> detail(@RequestBody CatBanner catBanner){
//		return catBannerService.selectOne(catBanner);
//	}
	
	@RequestMapping(method = RequestMethod.POST, value = "/page")
	@ApiOperation(value = "banner图列表")
	public R<Page<CatBanner>> page(@RequestBody PageParams<CatBannerQueryDto> pageParams){
	    Page<CatBanner> page = pageParams.buildSimplePage();
	    page.setOrders(Arrays.asList(OrderItem.asc("sort")));
	    boolean isQueryByPostion = pageParams.getModel()!=null && StrUtil.isNotBlank(pageParams.getModel().getPostion());
		return R.result(200, catBannerService.page(page,
                Wrappers.<CatBanner>lambdaQuery().eq(CatBanner::getStatus, 1)
                        .eq(isQueryByPostion, CatBanner::getPostion, isQueryByPostion ? pageParams.getModel().getPostion():null)),
                "success");
	}
	
//	@RequestMapping(method = RequestMethod.POST, value = "/add")
//	@ApiOperation(value = "新增")
//	public ResponseHeaderModel add(@RequestBody CatBanner catBanner){
//
//	   return catBannerService.add(catBanner);
//	}
//	@ApiOperation(value = "编辑")
//	@RequestMapping(method = RequestMethod.POST, value = "/modify")
//	public ResponseHeaderModel modify(@RequestBody CatBanner catBanner){
//
//	   return catBannerService.modify(catBanner);
//	}
	
}

